#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;
const int N = 2e5 + 10;
int n;
int a[N];

int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int t; cin >> t;
    while(t--){
        cin >> n;
        for(int i = 1; i <= n; ++i){
            cin >> a[i];
        }
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= n; ++j){
                if(gcd(a[i]+a[j],a[i+1]+a[j+1]) >= 3){
                    cout << a[j] << " ";
                }
            }
        }
    }
    
    return 0;
}